package cz.muni.fi.pb138.xml.wrda.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Michal Krajcovic <422783@mail.muni.cz>
 * @version 4/28/14
 */
public class ApplicationContextWrapper implements ApplicationContextAware {

    private static ApplicationContext appContext;
    private final static ApplicationContextWrapper instance = new ApplicationContextWrapper();

    private ApplicationContextWrapper(){
        setApplicationContext(new ClassPathXmlApplicationContext("applicationContext.xml"));
    }

    @Override
    public void setApplicationContext(ApplicationContext appContext) throws BeansException {
        this.appContext = appContext;
    }

    public static ApplicationContext getApplicationContext(){
        return appContext;
    }

    @SuppressWarnings("unchecked")
    public static <T> T getBean(String beanName)
    {
        return (T) appContext.getBean(beanName);
    }
}
